﻿using DevExpress.XtraEditors;
using DXApplication_TestDemo.Models.ProgramModel;
using DXApplication_TestDemo.ViewModels;

namespace DXApplication_TestDemo.Views
{
    public partial class SettingView : DevExpress.XtraEditors.XtraForm
    {
        public SettingView()
        {
            InitializeComponent();

            //使用单例vm保证数据一致性
            mvvmContext1.SetViewModel(typeof(SettingViewModel), ProgramModel.Instance.SettingViewModels);

            InitializeBindings();

            var fluent = mvvmContext1.OfType<SettingViewModel>();

            //触发器
            fluent.SetTrigger(x => x.SettingModels.Test, (x) =>
            {
                if (x == 123)
                {
                    XtraMessageBox.Show($"触发器--{x}");
                }
            });

        }

        //初始化绑定
        void InitializeBindings()
        {
            //var viewModel = mvvmContext1.OfType<SettingViewModel>().ViewModel;
            var viewModel = mvvmContext1.GetViewModel<SettingViewModel>();

            labelControl1.DataBindings.Add("Text", viewModel.SettingModels, "Test", true);
            textEdit1.DataBindings.Add("Text", viewModel.SettingModels, "Test", true);

            simpleButton1.BindCommand(viewModel.SendDataCommand);



        }
    }
}